Mission editor WYSIWYG Text Editor

James Peret 10 years ago
parent
commit
ad2a2d30a9

+ 53 - 3
app/assets/javascripts/blog_posts.js.coffee

@@ -1,6 +1,53 @@
1
+attachSummernoteMissionHandler = ->
1 2
 
3
+  # to set summernote object
4
+  # You should change '#post_content' to your textarea input id
5
+  summer_note = $('#briefing_content')
6
+
7
+  # to call summernote editor
8
+  summer_note.summernote
9
+    # to set options
10
+    height:400
11
+    onImageUpload: (files, editor, welEditable) ->
12
+      sendFile files[0], editor, welEditable
13
+        
14
+    toolbar: [
15
+                ["style", ["style"]],
16
+			 ["style", ["bold", "italic", "underline", "clear"]],
17
+			 ["fontsize", ["fontsize"]],
18
+			 ['insert', ['picture', 'link']],
19
+                ["layout", ["ul", "ol", "paragraph"]],
20
+			 ["table", ["table"]],
21
+                ["code", ["codeview"]]
22
+             ]
2 23
 
3
-attachRatingHandler = ->
24
+  # to set code for summernote
25
+  summer_note.code summer_note.val()
26
+
27
+  # to get code for summernote
28
+  summer_note.closest('form').submit ->
29
+    # alert $('#post_content').code()
30
+    summer_note.val summer_note.code()
31
+    true
32
+
33
+sendFile = (file, editor, welEditable) ->
34
+	data = new FormData()
35
+	data.append("file", file)
36
+	$.ajax {
37
+		url: '/upload',
38
+		data: data,
39
+		cache: false,
40
+		contentType: false,
41
+		processData: false,
42
+		type: 'POST',
43
+		success: (data) ->
44
+			editor.insertImage(welEditable, data.url)
45
+		error: (data) ->
46
+			editor.insertImage(welEditable, data.url)
47
+			alert(data.url)
48
+	}   
49
+
50
+attachSummernoteBlogHandler = ->
4 51
 
5 52
   $(".bootstrap_switch").bootstrapSwitch('size', 'large');
6 53
 
@@ -53,5 +100,8 @@ sendFile = (file, editor, welEditable) ->
53 100
 			alert(data.url)
54 101
 	}    
55 102
     
56
-$(document).ready attachRatingHandler
57
-$(document).on "page:load", attachRatingHandler
103
+$(document).ready attachSummernoteBlogHandler
104
+$(document).on "page:load", attachSummernoteBlogHandler
105
+
106
+$(document).ready attachSummernoteMissionHandler
107
+$(document).on "page:load", attachSummernoteMissionHandler

+ 0 - 1
app/assets/javascripts/mission_editor.js

@@ -19,7 +19,6 @@ function attachHandler(jQuery) {
19 19
 	$('.dropdown-toggle').dropdown();
20 20
 	
21 21
 	$('.dropdown-toggle').on('show.bs.dropdown', function () {
22
-		alert('asdfsf')
23 22
 		$(this).parent().parent().parent().addClass("overflow");
24 23
 	  
25 24
 		

+ 4 - 0
app/assets/stylesheets/mission_editor.css.less

@@ -225,4 +225,8 @@ span.btn-file .form-group {
225 225
 	     margin-left: 10px;
226 226
 	     padding-right: 0px;
227 227
 	}
228
+}
229
+
230
+.note-toolbar.btn-toolbar .btn {
231
+	border: 1px solid @medium-gray;
228 232
 }

+ 1 - 1
app/views/mission_editor/agents/_form.html.erb

@@ -12,7 +12,7 @@
12 12
 							<%= content_tag(:div, class: "form-inputs") do %>
13 13
 							    <%= f.text_field :role, label: (t 'mission_editor.agents.role'), class: 'input-block-level' %>
14 14
 							    <% f.text_area :objective, label: (t 'mission_editor.agents.objective'), class: 'input-block-level', rows: 5 %>
15
-							    <%= f.text_area :briefing, label: (t 'mission_editor.mission_details.briefing'), class: 'input-block-level', rows: 10 %>
15
+							    <%= f.text_area :briefing, label: (t 'mission_editor.mission_details.briefing'), class: 'input-block-level summernote', rows: 15, id: 'briefing_content' %>
16 16
 							<% end %>
17 17
 						<% end %>
18 18
 					<% end %>

+ 1 - 1
app/views/missions/_form.html.erb

@@ -7,10 +7,10 @@
7 7
 				<%= content_tag(:div, class: "form-inputs") do %>
8 8
 				    <%= f.text_field :title, label: (t 'mission_editor.mission_details.mission_title'), class: 'input-block-level' %>
9 9
 				    <%= f.text_field :objective, label: (t 'mission_editor.mission_details.mission_objective'), class: 'input-block-level' %>
10
-				    <%= f.text_area :briefing, label: (t 'mission_editor.mission_details.mission_briefing'), class: 'input-block-level', rows: 10 %>
11 10
 				    <%= f.select :language, [[(t 'mission_editor.mission_details.en'), 'en'], [(t 'mission_editor.mission_details.pt-BR'), 'pt-BR']], { label: (t 'mission_editor.mission_details.language') }, { class: "selectpicker" } %>
12 11
 					<%= render :partial => 'mission_image_uploader', locals: { mission: @mission, f: f } %>
13 12
 					<%= f.text_field :video, label: (t 'mission_editor.mission_details.youtube_video_link'), class: 'input-block-level' %>
13
+					<%= f.text_area :briefing, label: (t 'mission_editor.mission_details.mission_briefing'), class: 'input-block-level summernote', rows: 15, id: 'briefing_content'  %>
14 14
 					<%= content_tag(:div, '', class: 'inline-form-line') do%>
15 15
 						<%= f.select :duration_scale, [[(t 'time.days'), 'days'], [(t 'time.hours'), 'hours']], { label: (t 'mission_editor.mission_details.mission_duration') }, { class: "selectpicker", layout: :inline } %>
16 16
 						<%= f.number_field :duration_number, hide_label: true, placeholder: (t 'mission_editor.mission_details.duration') %>

+ 3 - 3
app/views/missions/show.html.erb

@@ -7,11 +7,11 @@
7 7
 		<%= content_tag(:div, class: 'span8 mission-briefing') do %>
8 8
 			
9 9
 			<% if @mission.objective != nil %>
10
-				<%= content_tag(:h4, ((t 'mission.objective') + ':') ) %>
11
-				<%= @mission.objective.html_safe %>
10
+				<% content_tag(:h4, ((t 'mission.objective') + ':') ) %>
11
+				<% @mission.objective.html_safe %>
12 12
 			<% end %>
13 13
 			
14
-			<%= content_tag(:h4, ((t 'mission.briefing') + ':') ) %>
14
+			<% content_tag(:h4, ((t 'mission.briefing') + ':') ) %>
15 15
 			<%= @mission.briefing.html_safe %>
16 16
 			
17 17
 			

+ 2 - 2
app/views/missions/show_agent_details.html.erb

@@ -25,7 +25,7 @@
25 25
 				<%= content_tag(:p, @agent.objective.html_safe) %>
26 26
 			<% end %>
27 27
 			<% if @agent.briefing != nil %>
28
-				<%= content_tag(:h4, ((t 'mission.instructions') + ':') ) %>
28
+				<% content_tag(:h4, ((t 'mission.instructions') + ':') ) %>
29 29
 				<%= @agent.briefing.html_safe if @agent.briefing  %>
30 30
 			<% end %>
31 31
 		<% end %>
@@ -69,7 +69,7 @@
69 69
 			<% end %>
70 70
 		<% end %>
71 71
 	<% end %>
72
-	<%= content_tag(:div, class: 'row') do %>
72
+	<%= content_tag(:div, class: 'row', style: 'margin-top: 25px;') do %>
73 73
 		<%= content_tag(:div, class: 'span12 panel-group accordion', id: 'colapse_steps') do %>
74 74
 			<%= content_tag(:h4, ((t 'agent.tasks') + ':') ) %>
75 75
 			<% # Steps %>

BIN
dump.rdb